﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DAO;
using DTO;

namespace QLDaiLy
{
    public partial class QuanLyDaiLy : RibbonForm
    {
        string MaNhanVien;
        int MaChucVu;
        public QuanLyDaiLy()
        {
            InitializeComponent();
           // LoadDangNhap();
            LoadGiaoDienMacDinh();
            barButtonItemDoiMatKhau.Enabled = false;
            barButtonItemLogin.Enabled = true;
            barButtonItemDangXuat.Enabled = false;
          //  PhanQuyen_MacDinh();
           // PhanQuyen_MacDinh();
            
        }
       // BindingList<Person> gridDataList = new BindingList<Person>();
        private void LoadGiaoDienMacDinh()
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            GiaoDienMacDinh frm = new GiaoDienMacDinh();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void LoadGiaoDienWellCome()
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            GiaoDienWellcome frm = new GiaoDienWellcome();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void LoadDangNhap()
        {
        
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DangNhap frm = new DangNhap();
            frm.sender = new DangNhap.SEND(getString);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        public  void getString(string id, string maLND)
        {
            DataTable dt = ChucVuDAO.ChucVu(int.Parse(maLND));
            MaNhanVien = id;
            MaChucVu = int.Parse(maLND);
            barButtonItemLogin.Enabled = false;
            barButtonItemDoiMatKhau.Enabled = true;
            barButtonItemDangXuat.Enabled = true;
            if (dt.Rows[0][1].ToString() == "Admin")
            {
                barTenChucVu.Caption = "Chào: " + dt.Rows[0][1];
                barButtonChucVu.Caption = "Nhân Viên: " + id;
                PhanQuyen_Admin();
            }
            if (dt.Rows[0][1].ToString() == "Quản lý")
            {
                barTenChucVu.Caption = "Chào " + dt.Rows[0][1];
                barButtonChucVu.Caption = "Nhân Viên: " + id;
                PhanQuyen_QuanLy();
            }
            if (dt.Rows[0][1].ToString() == "Nhân Viên Tiếp Nhận")
            {
                barTenChucVu.Caption = "Chào " + dt.Rows[0][1];
                barButtonChucVu.Caption = "Nhân Viên: " + id;
                PhanQuyen_TiepNhan();
            }
            if (dt.Rows[0][1].ToString() == "Thu Ngân")
            {
                barTenChucVu.Caption = "Chào " + dt.Rows[0][1];
                barButtonChucVu.Caption = "Nhân Viên: " + id;
                PhanQuyen_ThuNgan();
            }
            if (dt.Rows[0][1].ToString() == "Thủ Kho")
            {
                barTenChucVu.Caption = "Chào " + dt.Rows[0][1];
                barButtonChucVu.Caption = "Nhân Viên: " + id;
                PhanQuyen_ThuKho();
            }
            LoadGiaoDienWellCome();
        }
        public void PhanQuyen_MacDinh()
        {
           // PhanQuyen_Goup();
            homeRibbonPage.Visible = true;
            ChucNang.Visible = false;
            ribbonQuanLyNhapXuat.Visible = false;
            quanLyQuiDinh.Visible = false;
            ribbonAdmin.Visible = false;

        }
        public void PhanQuyen_Goup()
        {
            ribbonPageGroupDL.Visible = false;
            ribbonPageGroupNV.Visible = false;
            ribbonPageGroupBaoCao.Visible = false;
            ribbonPageGroupQLXoa.Visible = false;
            ribbonPageGroupQD.Visible = false;
            ribbonPageGroupThuNgan.Visible = false;
            ribbonPageGroupThuKho.Visible = false;
            ribbonPageGroupHangHoa.Visible = false;
            ribonNhanVien.Visible = false;
            ribonNhanVienThoat.Visible = false;

        }
        public void PhanQuyen_GoupActice()
        {
            ribbonPageGroupDL.Visible = true;
            ribbonPageGroupNV.Visible = true;
            ribbonPageGroupBaoCao.Visible = true;
            ribbonPageGroupQLXoa.Visible = true;
            ribbonPageGroupQD.Visible = true;
            ribbonPageGroupThuNgan.Visible = true;
            ribbonPageGroupThuKho.Visible = true;
            ribbonPageGroupHangHoa.Visible = true;
            ribonNhanVien.Visible = true;
            ribonNhanVienThoat.Visible = true;

        }
        public void PhanQuyen_Admin()
        {
            ChucNang.Visible = false;
            quanLyQuiDinh.Visible = false;
            ribbonQuanLyNhapXuat.Visible = false;
           
        }
        public void PhanQuyen_QuanLy()
        {
            //  ribbonPageGroupHangHoa.Visible = false;
            ChucNang.Visible = false;
            ribbonAdmin.Visible = false;
            ribbonQuanLyNhapXuat.Visible = false;

        }
        public void PhanQuyen_TiepNhan()
        {
            quanLyQuiDinh.Visible = false;
            ribbonQuanLyNhapXuat.Visible = false;
            ribbonAdmin.Visible = false;

        }
        public void PhanQuyen_ThuKho()
        {
           // barPhieuThuTien.Enabled = false;
            ribbonQuanLyNhapXuat.Visible = true;
            ChucNang.Visible = false;
            quanLyQuiDinh.Visible = false;
            ribbonAdmin.Visible = false;
            //ribbonPageGroupThuNgan.Enabled = false;
            ribbonPageGroupThuNgan.Visible = false;
        }
        public void PhanQuyen_ThuNgan()
        {
            ribbonPageGroupHangHoa.Visible = false;
            ribbonQuanLyNhapXuat.Visible = true;
            ChucNang.Visible = false;
            quanLyQuiDinh.Visible = false;
            ribbonAdmin.Visible = false;
            //ribbonPageGroupThuNgan.Enabled = false;
            ribbonPageGroupThuKho.Visible = false;
           // barPhieuXuat.Enabled = false;

        }
        private void barDaiLyThoat_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Close();
            
        }
        private void barButtonItem24_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            ThemMatHang frm = new ThemMatHang();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barNhapKho_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            NhapKho frm = new NhapKho();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barXoaNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachNhanVien frm = new DanhSachNhanVien();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barDanhSachNhanVienMoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachNhanVienMoi frm = new DanhSachNhanVienMoi();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barPhanQuyenNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            PhanQuyen frm = new PhanQuyen();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barResetMatKhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            ResetMatKhau frm = new ResetMatKhau();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDanhSachDaiLy_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            XemDanhSachDaiLy frm = new XemDanhSachDaiLy();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemLogin_ItemClick(object sender, ItemClickEventArgs e)
        {
            
            LoadDangNhap();
        }
        private void barButtonItemDangXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            //barDangNhap.Enabled = true;
            barButtonItemDoiMatKhau.Enabled = false;
            barButtonItemLogin.Enabled = true;
            barButtonItemDangXuat.Enabled = false;
            PhanQuyen_MacDinh();
            PhanQuyen_GoupActice();
            LoadDangNhap();
            barTenChucVu.Caption = "";
            barButtonChucVu.Caption = "Chưa Đăng Nhập";
        }
        private void barButtonItemDoiMatKhau_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DoiMatKhau frm = new DoiMatKhau(MaNhanVien);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);

        }
        private void barButtonItemTimKiemDaiLy_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            TraCuuCoBan frm = new TraCuuCoBan(MaChucVu);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDs_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            XemDanhSachDaiLy frmtndl = new XemDanhSachDaiLy(MaChucVu);
            frmtndl.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frmtndl, 0, 1);
        }
        private void barButtonItemDSNC_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            TimKiemNangCao frm = new TimKiemNangCao(MaChucVu);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemTimNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            TraCuuNhanVien frm = new TraCuuNhanVien(MaChucVu);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonTiepNhanDL_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            frmTiepNhanDaiLy frm = new frmTiepNhanDaiLy(MaNhanVien);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonDanhSachNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachNhanVien frm = new DanhSachNhanVien();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemThemNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            TiepNhanNhanVien frm = new TiepNhanNhanVien();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDaiLyXoa_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachDaiLyCanXoa frm = new DanhSachDaiLyCanXoa();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDSPhieuXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachPhieuXuat frm = new DanhSachPhieuXuat();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDSPhieuThu_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachCacPhieuThu frm = new DanhSachCacPhieuThu();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemPhieuThu_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            PhieuThuTien frm = new PhieuThuTien(MaNhanVien);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemHoaDon_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            PhieuXuat frm = new PhieuXuat(MaNhanVien);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemDSDaiLyHoaDon_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            XemDanhSachDaiLy frm = new XemDanhSachDaiLy();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemCapNhatGia_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            CapNhatGia frm = new CapNhatGia();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemXoaNV_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachNhanVien frm = new DanhSachNhanVien(MaChucVu);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }
        private void barButtonItemNhanVienMoi_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachNhanVienMoi frm = new DanhSachNhanVienMoi(MaChucVu);
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemNhapKho_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            NhapKho frm = new NhapKho();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemBaoCaoDoanhSo_ItemClick(object sender, ItemClickEventArgs e)
        {

            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            BaoCaoDoanhSo frm = new BaoCaoDoanhSo();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemPhanQuyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            PhanQuyen frm = new PhanQuyen();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemCapNhatDaiLy_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            CapNhatDaiLy frm = new CapNhatDaiLy();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemDSDLDangNo_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            DanhSachDaiLyDangNo frm = new DanhSachDaiLyDangNo();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemTimNangCao_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            TinNhanVienNangCao frm = new TinNhanVienNangCao();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

        private void barButtonItemBaoCaoCongNo_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (tableLayoutPanelMain.GetControlFromPosition(0, 1) != null)
            {
                tableLayoutPanelMain.Controls.Remove(tableLayoutPanelMain.GetControlFromPosition(0, 1));
            }
            BaoCaoCongNo frm = new BaoCaoCongNo();
            frm.Size = this.Size;
            tableLayoutPanelMain.Controls.Add(frm, 0, 1);
        }

    }
}